﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dln.Common.Helper;
using Dln.Model;


public partial class Page_Community_DoctorIndex : System.Web.UI.Page
{
    protected string DoctorCardId = string.Empty;
    protected string openid = string.Empty;
    protected IList<Community_Topic> CommunityTopicList = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        //openid = GetAuthOpenId();
        openid = "oF6dUwxAa6BtWPqaRnE_lz7lDBgQ";
        var WeChatUsers = SqlHelper.Context.From<WeChatUsers>().Where(d => d.Openid == openid && d.DelStatus == 0);
        if (WeChatUsers != null && WeChatUsers.Count() > 0 && !string.IsNullOrEmpty(WeChatUsers.ToFirstDefault().CardID))
        {
            DoctorCardId = "1";
            var model = SqlHelper.Context.From<Community_Topic>().Where(d => d.CardId == DoctorCardId && d.DelStatus == 0);
            if (model != null && model.Count() > 0)
            {
                CommunityTopicList = model.ToList();
                foreach (var item in CommunityTopicList)
                {
                    var replyModel = SqlHelper.Context.From<Community_TopicReply>().Where(d => d.ReplyId == item.Id && d.Delstatus == 0 && d.IsRead == 0);
                    if (replyModel != null && replyModel.Count() > 0)
                    {
                        item.Number = replyModel.Count();
                    }
                }
                CommunityTopicList = CommunityTopicList.OrderByDescending(d => d.Number).ToList();
            }
        }

    }
}